// 懒加载
// const Home = () => import("@/pages/Home");
// const Login = () => import("@/pages/Login");
// const Search = () => import("@/pages/Search");
// const Register = () => import("@/pages/Register");

// 懒加载写法2：
export default [
  {
    path: "/",
    redirect: "/home",
  },
  {
    path: "/home",
    name: "Home",
    component: () => import("@/pages/Home"),
  },
  {
    path: "/login",
    name: "Login",
    component: () => import("@/pages/Login"),
    // 给不展示的路由设置元信息为true 没有设置的会默认是false
    meta: {
      isHidden: true,
    },
  },
  {
    path: "/search/:keyword?",
    name: "Search",
    component: () => import("@/pages/Search"),
  },
  {
    path: "/register",
    name: "Register",
    component: () => import("@/pages/Register"),
    meta: {
      isHidden: true,
    },
  },
  {
    path: "/detail/:skuId",
    name: "Detail",
    component: () => import("@/pages/Detail"),
  },
  {
    path: "/addCartSuccess",
    name: "addCartSuccess",
    component: () => import("@/pages/AddCartSuccess"),
    beforeEnter: (to, from, next) => {
      if (from.name === "Detail") {
        next();
      } else {
        next("/detail");
      }
    },
  },
  {
    path: "/shopCart",
    name: "shopCart",
    component: () => import("@/pages/ShopCart"),
  },
  {
    path: "/trade",
    name: "trade",
    component: () => import("@/pages/Trade"),
    beforeEnter: (to, from, next) => {
      if (from.name === "shopCart") {
        next();
      } else {
        next("/shopCart");
      }
    },
  },
  {
    path: "/pay",
    name: "pay",
    component: () => import("@/pages/Pay"),
    //路由独享守卫
    beforeEnter(to, from, next) {
      if (from.name === "trade") {
        next();
      } else {
        next("/shopCart");
      }
    },
  },
  {
    path: "/paySuccess",
    name: "paySuccess",
    component: () => import("@/pages/PaySuccess"),
    //路由独享守卫
    beforeEnter(to, from, next) {
      if (from.name === "pay") {
        next();
      } else {
        next("/shopCart");
      }
    },
  },
  {
    path: "/center",
    redirect: "/center/myOrder",
    component: () => import("@/pages/Center"),
    children: [
      {
        path: "myOrder",
        name: "myOrder",
        component: () => import("@/pages/Center/components/MyOrder"),
      },
      {
        path: "teamOrder",
        name: "teamOrder",
        component: () => import("@/pages/Center/components/TeamOrder"),
      },
    ],
  },
];
